<template>
  <div>
    <span>
      <h2>巡检审核</h2>
    </span>
    <!-- 搜索框 -->
    <el-form :inline="true" :model="check1" class="demo-form-inline">
      <el-row>
        <el-col :span="5">
          <el-form-item label="任务编号">
            <el-input v-model="check1.taskno" placeholder="请输入编号"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="任务名称">
            <el-input v-model="check1.taskname" placeholder="请输入计划名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="任务类型" label-width="80px">
            <el-select v-model="check1.tasktype" placeholder="请选择">
              <el-option label="计划任务" value="plan">计划任务</el-option>
              <el-option label="紧急任务" value="temp">紧急任务</el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="审核状态" label-width="80px">
            <el-select v-model="check1.taskstatu" placeholder="请选择">
              <el-option label="等待审核" value="2">等待审核</el-option>
              <el-option label="审核通过" value="3">审核通过</el-option>
              <el-option label="审核不通过" value="4">审核不通过</el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button type="primary" @click="list">查询</el-button>
            <el-button type="info" @click="clear" style="margin-left: 10px;">清空</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <!-- 搜索框 -->
    <!-- 表格开始 -->
    <el-table :data="checkList" border style="width: 100%">
      <el-table-column prop="id" label="序号"> </el-table-column>
      <el-table-column prop="taskno" label="任务编号"> </el-table-column>
      <el-table-column prop="taskname" label="任务名称"> </el-table-column>
      <el-table-column label="任务类型">
        <template slot-scope="scope">
          <span>{{
            scope.row.tasktype == "plan" ? "计划任务" : "紧急任务"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="enddate" label="结束日期"> </el-table-column>
      <el-table-column prop="executor" label="执行人"> </el-table-column>
      <el-table-column prop="taskstatu" label="审核状态">
        <template slot-scope="scope">
          <span>{{
            scope.row.taskstatu == 0
              ? "待执行"
              : scope.row.taskstatu == 1
                ? "执行中"
                : scope.row.taskstatu == 2
                  ? "等待审核"
                  : scope.row.taskstatu == 3
                    ? "审核通过"
                    : "审核不通过"
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="warning" @click="showCheck(scope.row)">审核</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格结束 -->

    <!-- 分页开始 -->
    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageInfo.pageNum" :page-sizes="[5, 10, 20]" :page-size="pageInfo.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pageInfo.total">
    </el-pagination>
    <!-- 分页结束 -->

    <!-- 审核表单开始 -->
    <el-dialog title="任务审核" :visible.sync="dialogVisibleCheck" width="30%">
      <el-form label-width="150px" :model="check">
        <el-row>
          <el-col>
            <el-form-item label="审核结果" label-width="80px">
              <el-radio v-model="check.taskstatu" :label="3">审核通过</el-radio>
              <el-radio v-model="check.taskstatu" :label="4">审核不通过</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleCheck = false">取 消</el-button>
        <el-button type="primary" @click="checkSuccess()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 审核表单结束 -->
  </div>
</template>
<script>
export default {
  data() {
    return {
      checkList: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 5,
      },
      dialogVisibleCheck: false,
      check: {
        taskstatu: "",
      },
      check1: {
        taskno: "",
        taskname: "",
        tasktype: "",
        taskstatu: ""
      }
    };
  },
  methods: {
    clear() {
      this.check1 = {}
    },
    checkSuccess() {
      this.$axios
        .put("/patrolcheck/updateCheck", this.check)
        .then((result) => {
          let vo = result.data;
          if (vo.code == 200) {
            this.$message(vo.message);
            this.dialogVisibleCheck = false;
            this.list();
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    showCheck(row) {
      this.check.id = row.id;
      this.check.taskstatu = row.taskstatu;
      this.dialogVisibleCheck = true;
    },
    handleCurrentChange(num) {
      this.pageInfo.pageNum = num;
      this.list();
    },
    handleSizeChange(size) {
      this.pageInfo.pageSize = size;
      this.list();
    },
    list() {
      this.$axios
        .get("/patrolcheck/findAll", {
          params: {
            pageNum: this.pageInfo.pageNum,
            pageSize: this.pageInfo.pageSize,
            taskno: this.check1.taskno,
            taskname: this.check1.taskname,
            tasktype: this.check1.tasktype,
            taskstatu: this.check1.taskstatu
          },
        })
        .then((result) => {
          let vo = result.data;
          if (vo.code == 200) {
            this.pageInfo.total = vo.data.total;
            this.checkList = vo.data.list;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  mounted() {
    this.list();
  },
};
</script>
<style>
.a {
  margin-left: 0px;
}
</style>